package com.duanjw.mybatis.spring;

import com.duanjw.mybatis.spring.config.AppConfig;
import com.duanjw.mybatis.spring.service.UserService;
import com.duanjw.mybatis.spring.service.impl.UserServiceImpl;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.List;

/**
 * @author duanjw
 */
public class MybatisSpringApplication {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext cxt = new AnnotationConfigApplicationContext(AppConfig.class);

//        SqlSessionTemplate bean = cxt.getBean(SqlSessionTemplate.class);
//        List<Object> objects = bean.selectList("select * from user;");
//        objects.forEach(item -> System.out.println(item));

//        UserService userService = cxt.getBean(UserServiceImpl.class);
        UserService userService = cxt.getBean(UserServiceImpl.class);
        userService.list().forEach(item -> System.out.println(item));
    }
}
